/*************************************************
 * 
 * Copyright by Bruno Eberhard
 * 
 * Created on 02.06.2006
 *
 *************************************************/
package fightplan.core;

import java.awt.Color;

import fightplan.business.ValueValidation;

public class NotZeroValidation implements ValueValidation {

	private Color severityIfInvalid = YELLOW;
	private String textIfInValid = "0 ist Standardwert.";

	public NotZeroValidation() {

	}

	public Color validationColor(Object validatable) {
		if (validatable instanceof String) {
			String s = (String) validatable;
			while (s.length() > 0 && !Character.isDigit(s.charAt(s.length() - 1))) {
				s = s.substring(0, s.length() - 1);
			}
			if (Long.parseLong(s) == 0) {
				return severityIfInvalid;
			} else {
				return null;
			}
		} else if (validatable instanceof Number) {
			Number n = (Number) validatable;
			if (n.longValue() == 0) {
				return severityIfInvalid;
			} else {
				return null;
			}
		} else {
			return YELLOW;
		}
	}

	public String validationText(Object validatable) {
		if (validatable instanceof String) {
			String s = (String) validatable;
			while (s.length() > 0 && !Character.isDigit(s.charAt(s.length() - 1))) {
				s = s.substring(0, s.length() - 1);
			}
			if (Long.parseLong(s) == 0) {
				return textIfInValid;
			} else {
				return null;
			}
		} else if (validatable instanceof Number) {
			Number n = (Number) validatable;
			if (n.longValue() == 0) {
				return textIfInValid;
			} else {
				return null;
			}
		} else {
			return "Validierung fehlgeschlagen";
		}

	}

}